package com.vogue.supplymall.shop.domain.mapper;

import com.vogue.ssm.database.util.SqlLangDriver;
import com.vogue.supplymall.common.domain.dto.RelevanceInfo;
import com.vogue.supplymall.common.domain.dto.SearchInfo;
import com.vogue.supplymall.shop.domain.model.Relevance;
import com.vogue.supplymall.shop.domain.provider.ProductSqlProvider;
import com.vogue.supplymall.shop.domain.provider.RelevanceProductSqlProvider;
import com.vogue.supplymall.shop.domain.provider.RelevanceShopSqlProvider;

import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * The interface Relevance mapper.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-03-27
 */
@Mapper
public interface RelevanceMapper extends BaseMapper<Relevance, Long> {

    /**
     * Find relevance list.
     * 查询用户关注、收藏的信息，不能作为关注收藏列表使用
     *
     * @param relevanceInfo the relevance info
     * @return the list
     */
    @Select("select * from relevance where disabledflag = 0 and type = #{type} and originobjid = #{userId} " +
            "and targetobjtype = #{targetObjType}  and targetobjid = #{targetObjId}  ")
    @Lang(SqlLangDriver.class)
    List<Relevance> findRelevance(RelevanceInfo relevanceInfo);

    /**
     * Count watch map.
     *
     * @param originobjid the originobjid
     * @return the map
     */
    @Select("select COUNT(id) watch_count from relevance where originobjid = #{originobjid} and type= 1 and disabledflag = 0 and targetobjtype = 2 ")
    @Lang(SqlLangDriver.class)
    Map<String, Object> countWatch(Long originobjid);

    /**
     * Count collect map.
     *
     * @param originobjid the originobjid
     * @return the map
     */
    @Select("select COUNT(id) collect_count from relevance where originobjid = #{originobjid} and type= 1 and disabledflag = 0 and targetobjtype = 3 ")
    @Lang(SqlLangDriver.class)
    Map<String, Object> countCollect(Long originobjid);

    /**
     * Find product watch list.
     * 商品关注列表查询
     *
     * @param searchInfo the search info
     * @return the list
     */
    @SelectProvider(type = RelevanceProductSqlProvider.class, method = "find")
    List<Map<String,Object>> findProductWatch(SearchInfo searchInfo);

    /**
     * Find shop watch list.
     * 店铺关注列表查询
     *
     * @param searchInfo the search info
     * @return the list
     */
    @SelectProvider(type = RelevanceShopSqlProvider.class, method = "find")
    List<Map<String,Object>> findShopWatch(SearchInfo searchInfo);
}
